<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>

<head>
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css">
    <script src="${ctx}/layui/jquery.js"></script>
</head>

<body>
<div class="layui-card layui-anim layui-anim-upbit">
    <div class="layui-card-header">
        <!-- <i class="layui-icon layui-icon-website" style="font-size: 30px; color: #bbbbbb;"></i> -->
        <a onclick="prev()"><i class="layui-icon layui-icon-left"></i></a>
        <span style="font-size: 20px;">添加用户</span>
        <span style="float: right"> <a onclick="refresh()"><i class="layui-icon layui-icon-refresh"></i></a></span>
    </div>
    <blockquote class="layui-elem-quote">注意：密码和邮箱可二选一填写。若密码为空则通过邮箱发送验证邮件自定义密码，否则直接设置密码。</blockquote>
    <div class="layui-card-body">

        <form action="" class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input name="username" class="layui-input" lay-verType="tips"></input>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input name="password" class="layui-input" lay-verType="tips"></input>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input name="email" class="layui-input"  lay-ignore lay-verType="tips"></input>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button lay-submit class="layui-btn layui-btn-normal" lay-filter="ff">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>

    </div>
</div>


</body>
<script src="${ctx}/layui/layui.all.js"></script>
<script>
    layui.use(['form', 'element', 'laydate'], function() {
        var form = layui.form;
        var laydate = layui.laydate;
        form.on("submit(ff)", data => {
            $.ajax({
                url:"${ctx}/user/addUser",
                type:"post",
                dataType:"json",
                contentType:"application/json",
                data:JSON.stringify(data.field),
                success:res=>{
                    if(res.code==1){
                        <%--window.location.href = "${ctx}/home/index"--%>
                        layer.msg(res.data)
                    }else {
                        layer.msg(res.msg)
                    }

                },
                error:res=>{
                    alert(res.msg)
                }
            })

            return false;
        })
        laydate.render({
            elem: '#startTime'
        });
        laydate.render({
            elem: '#endTime'
        });
        // laydate.render({
        //     elem: '#startTime',
        //     position: 'static',

        //     calendar: true,

        // });
    })
</script>
<script>
    function prev() {
        history.go(-1);
    }

    function refresh() {
        window.location.reload()
    }

</script>
</html>
<style>

</style>